﻿using Helpers.Common;
using System;
using System.Configuration;
using System.Xml;

[Serializable]
public class ServiceConfiguration
{
    #region Properties

    /// <summary>
    /// The name or ip of the machine where the wcf service will be hosted.
    /// </summary>
    public string WcfServiceHost { get; set; }
    /// <summary>
    /// The port where the wcf service will be hosted.
    /// </summary>
    public int WcfServicePort { get; set; }
    /// <summary>
    /// The url where the wcf service will be hosted.
    /// </summary>
    public string WcfServiceUrl { get; set; }

    #endregion

    #region Constructors

    public ServiceConfiguration()
    {
        this.WcfServiceHost = "0.0.0.0";
        this.WcfServicePort = 80;
        this.WcfServiceUrl = "wcf";
    }

    #endregion

    #region Methods

    public override string ToString()
    {
        return "{" + HelperCommon.ObjectToString(this) + "}";
    }

    #endregion
}

/// <summary>
/// Handles the access to the ServiceConfiguration config section.
/// </summary>
public class ServiceConfigurationSectionHandler : IConfigurationSectionHandler
{
    /// <summary>
    /// Creates a ServiceConfiguration configuration section handler.
    /// </summary>
    /// <param name="parent">Parent object.</param>
    /// <param name="configContext">Configuration context object.</param>
    /// <param name="section">Section XML node.</param>
    /// <returns>The created section handler object.</returns>
    public object Create(object parent, object configContext, XmlNode section)
    {
        return XmlSerializer.LoadFromXmlString(section.OuterXml, typeof(ServiceConfiguration));
    }
}